import requests
import csv

headers = {'User-Agent':'你的Agent',
           'Cookie':'你的Cookie'
}


url = 'https://movie.douban.com/j/search_subjects'
params = {
    'type': 'movie',
    'tag': '热门',
    'page_limit': 10,
    'page_start': 0
}

response = requests.get(url, params=params)
data = response.json()

hot_movies = data['subjects']

with open('hot_movies.csv', 'w', newline='', encoding='utf-8') as csvfile:
    fieldnames = ['title', 'rate', 'url']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    for movie in hot_movies:
        writer.writerow({'title': movie['title'], 'rate': movie['rate'], 'url': movie['url']})